﻿using System;
using System.Reflection;
using TestAttribute;
using System.Collections.Generic;

/// <summary>
/// https://docs.microsoft.com/zh-cn/dotnet/api/system.attribute?redirectedfrom=MSDN&view=netframework-4.7.2
/// </summary>
class DemoClass
{

    static void Main(string[] args)
    {

        MsgCollectionHelper.CollectMsgFuncation();

        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("模拟消息执行");
        NetMsg netMsg = new NetMsg();

        netMsg.msgId = 100;
        netMsg.data = System.Text.Encoding.UTF8.GetBytes("角色登录成功,欢迎你!");
        var sender = Activator.CreateInstance(MsgCollectionHelper.msgDic[netMsg.msgId].sender, true);
        MsgCollectionHelper.msgDic[netMsg.msgId].methodInfo.Invoke(sender, new object[] { netMsg });

        netMsg.msgId = 103;
        netMsg.data = System.Text.Encoding.UTF8.GetBytes("角色升级啦!");
        sender = Activator.CreateInstance(MsgCollectionHelper.msgDic[netMsg.msgId].sender, true);
        MsgCollectionHelper.msgDic[netMsg.msgId].methodInfo.Invoke(sender, new object[] { netMsg });

        netMsg.msgId = 199;
        netMsg.data = System.Text.Encoding.UTF8.GetBytes("角色成功退出,谢谢!");
        sender = Activator.CreateInstance(MsgCollectionHelper.msgDic[netMsg.msgId].sender, true);
        MsgCollectionHelper.msgDic[netMsg.msgId].methodInfo.Invoke(sender, new object[] { netMsg });

        Console.ReadLine();
    }
}